package org.elip.teststatistics.client.ui;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.TextBox;

public class TestStatisticsPanel extends HorizontalPanel {
	
	private TextBox _failedTextBox;
	private TextBox _passedTextBox;
	private TextBox _skippedTextBox;
	
	private Label _failedLabel;
	private Label _passedLabel;
	private Label _skippedLabel;
	
	public TestStatisticsPanel() {

		setHorizontalAlign(HorizontalAlignment.CENTER);
		addStyleName("background-color-container");
		setWidth("100%");
		setHeight(44);
		setTableWidth("100%");
		
		this._failedLabel = new Label("Failed :");
		this._failedTextBox = new TextBox();
		this._passedLabel = new Label("Passed :");
		this._passedTextBox = new TextBox();
		this._skippedLabel = new Label("Skipped :");
		this._skippedTextBox = new TextBox();
	}
	
	@Override
	protected void onRender(Element parent, int pos) {
		super.onRender(parent, pos);
		
		HorizontalPanel testStatisticsForm = new HorizontalPanel();
		testStatisticsForm.setSpacing(10);
		testStatisticsForm.addStyleName("background-color-container");
		testStatisticsForm.setVerticalAlign(VerticalAlignment.MIDDLE);
		
		_failedLabel.addStyleName("text-red");
		_passedLabel.addStyleName("text-green");
		_skippedLabel.addStyleName("text-yellow");
		
		_failedTextBox.addStyleName("x-text-border");
		_failedTextBox.setWidth(30 + "px");
		
		_passedTextBox.addStyleName("x-text-border");
		_passedTextBox.setWidth(30 + "px");
		
		_skippedTextBox.addStyleName("x-text-border");
		_skippedTextBox.setWidth(30 + "px");
		
		testStatisticsForm.add(_failedLabel);
		testStatisticsForm.add(_failedTextBox);
		testStatisticsForm.add(_passedLabel);
		testStatisticsForm.add(_passedTextBox);
		testStatisticsForm.add(_skippedLabel);
		testStatisticsForm.add(_skippedTextBox);
		add(testStatisticsForm);
	}
	
	public void setPassed(int numb) {
		_passedTextBox.setText("" + numb);
	}
	
	public void setFailed(int numb) {
		_failedTextBox.setText("" + numb);
	}
	
	public void setSkipped(int numb) {
		_skippedTextBox.setText("" + numb);
	}
	
	public int getPassed() {
		return Integer.parseInt(_passedTextBox.getText());
	}
	
	public int getFailed() {
		return Integer.parseInt(_failedTextBox.getText());
	}
	
	public int getSkipped() {
		return Integer.parseInt(_skippedTextBox.getText());
	}
}
